#ifndef __RTUBUFFER_H__
#define __RTUBUFFER_H__
#include <map>
#include <string>
/**
 * @brief 缓存的寄存器数据单元
 * 
 */
typedef struct
{
    uint16_t data;  /*< 寄存器数据值*/
    uint8_t status; /*< 读取状态，未成功读取则自增，成功读取赋0，初始化为0xFF*/
}RegDataType;

typedef std::map<uint8_t,std::map<uint8_t,std::map<uint16_t,RegDataType>>> RTUBbuffer;
/**
 * @brief Modbus查询指令
 * 
 */
typedef struct
{
    uint8_t func;
    uint8_t slave;
    uint16_t addr;
    int nb;
}PollingCode,RequestCode;

void init_buffer();
bool ModbusBufferWriteByte(uint8_t slave,uint8_t func,uint16_t addr,uint16_t data);
bool ModbusBufferReadByte(uint8_t slave,uint8_t func,uint16_t addr,uint16_t *data);
bool ModbusBufferWrite(uint8_t slave,uint8_t func,uint16_t addr,int nb,uint16_t *data);
bool ModbusBufferRead(uint8_t slave,uint8_t func,uint16_t addr,int nb,uint16_t *data);
void ModbusBufferSetByteMiss(uint8_t slave,uint8_t func,uint16_t addr);
void ModbusBufferSetMiss(uint8_t slave,uint8_t func,uint16_t addr,int nb);
void ModbusBufferInsert(uint8_t slave, uint8_t func, uint16_t addr, uint16_t data);
#endif